package com.gw.quotes.net.service;

import java.util.List;

import org.ksoap2.serialization.SoapObject;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.gw.quotes.entity.business.SearchPriceList;
import com.gw.quotes.net.NewException;
import com.gw.quotes.net.Request;
import com.gw.quotes.net.Response;
import com.yxw.util.StringUtils;

/**
 * 搜索searcpricelist
 * 
 * @author Administrator
 * 
 */
public class PriceListSearchServiceImpl extends WebBaseServiceImpl {

	@Override
	public Response setResponse() {
		return new SearchPriceList();
	}

	@Override
	public void checkParam(Request request) throws NewException {
		if (request == null) {
			throw new NewException(Response.RESULT_ERROR, "传入request不能为空");
		}
		if (StringUtils.isEmpty(request.getName())) {
			throw new NewException(Response.RESULT_ERROR, "传入name不能为空");
		}
	}

	@Override
	public void setParamByRequest(Request request, SoapObject rpc)
			throws NewException {
		if (request.getName() == null || request.getName().trim().equals("")) {
			return;
		}
		String arg0 = "{'name':'" + request.getName()
				+ "','pagesize':'" + request.getPageSize()
				+ "','pageno':'" + request.getPageNo()+ "'}";
		rpc.addProperty("arg0", arg0);
	}

	@Override
	public String getMethodName() throws NewException {
		return "searchPriceList";
	}

	@Override
	public void resolveResponse(Object object, Response response)
			throws NewException {
		try {
			Gson gson = new Gson();
			java.lang.reflect.Type type = new TypeToken<SearchPriceList>() {
			}.getType();
			SearchPriceList searchPriceList = gson.fromJson(object.toString(),
					type);
			if (searchPriceList != null
					&& searchPriceList.getPricelist() != null) {
				searchPriceList.setResult(Response.RESULT_SUCCESS);
				setResponse(searchPriceList);
			}
		} catch (Exception e) {
			response.setMsg("获取失败");
			response.setResult(Response.RESULT_ERROR);
		}
	}

}
